package com.onewo.arthasdemo.server;

import com.onewo.arthasdemo.handler.Handler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.internal.StringUtil;

import java.util.logging.Logger;

public class DiscardServerHandler extends ChannelInboundHandlerAdapter {

    private static final Logger LOG = Logger.getLogger(DiscardServerHandler.class.getName());

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        final String message = new String(msg.toString().getBytes());
        LOG.info("客户端地址:"+ctx.channel().remoteAddress()+",消息:"+message);
        if (StringUtil.isNullOrEmpty(message)){
            return;
        }
        new Handler().enhance(message);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}